package com.talent.carrot.A_helloworld;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * 躲了一辈子雨，雨会不会很难过。
 * </p>
 * Created by zhumenglong on 2017/6/10.
 */
public class Send {

    private final static String QUEUE_NAME = "hello";

    public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("192.168.109.129");
        factory.setUsername("rabbit");
        factory.setPassword("rabbit");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        // 声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        String message = "Hello World!";

        for (int i = 0; i < 100000000; i++) {
            String messageTemp = message + i;
            channel.basicPublish("", QUEUE_NAME, null, messageTemp.getBytes("UTF-8"));
            System.out.println(" [x] Sent '" + messageTemp + "'");
        }

        channel.close();
        connection.close();
    }
}
